import { message } from "antd"
import {
  RechargeList,
  RechargeListPage,
  RechargeListSearch,
  RechargeListPageSearch

}  from '../services/chargeList';


export default {
  namespace: 'chargeList',

  state: {
    RehargeItem:{},
  },

  effects: {
    *RechargeList({payload}, { call, put }) {
      const data = yield call(RechargeList, payload);
      if(data.status == 0){
        yield put({
          type: 'updateState',
          payload: {
            RehargeItem:data.result
          }
        })
      }else{
       message.error(`${data.message}`)
      }
    },

    *RechargeListPage({payload}, { call, put }) {
      const data = yield call(RechargeListPage,payload);
      if(data.status == 0){
        yield put({
          type: 'updateState',
          payload: {
            RehargeItem:data.result
          }
        })
      }else{
       message.error(`${data.message}`)
      }
    },

    *RechargeListSearch({payload}, { call, put }) {
      const data = yield call(RechargeListSearch,payload);
      if(data.status == 0){
        yield put({
          type: 'updateState',
          payload: {
            RehargeItem:data.result
          }
        })
      }else{
       message.error(`${data.message}`)
      }
    },


    *RechargeListPageSearch({payload}, { call, put }) {
      const data = yield call(RechargeListPageSearch,payload);
      if(data.status == 0){
        yield put({
          type: 'updateState',
          payload: {
            RehargeItem:data.result
          }
        })
      }else{
       message.error(`${data.message}`)
      }
    },


    // *updateRechargeConfig({payload}, { call, put }) {
    //   const data = yield call(updateRechargeConfig,payload);
    //   if(data.status == 0){
    //     message.success("编辑成功!")
    //      yield put({type:"getRechargeConfig"})
    //   }else{
    //     message.error(`${data.message}`)
    //   }
    // },


  },

  reducers: {
    updateState (state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === "/charge/list") {
          dispatch({ 
            type: "RechargeList",
            payload:{
              ...location.query
            } 
          });
        }
      });
    }
  },

};
